const {ccclass, property} = cc._decorator;

@ccclass
export default class Helloworld extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;
    @property(cc.Sprite)
    spr: cc.Sprite = null;
    @property(cc.Label)
    label2: cc.Label = null;
    @property
    text: string = 'hello';


    start () {
        // init logic
        this.label.string = this.text;


        var n = cc.find("label", this.node);
        var lb = n.getComponent("cc.Label");
        lb.string = "change";

        // 加载 Prefab
        cc.loader.loadRes("panle3D", function (err, prefab) {
            cc.log("__________________load__prefab___");
            var newNode = cc.instantiate(prefab);
            cc.director.getScene().addChild(newNode);
            newNode.setPosition(0,0);            
            
        });        
        //https://gitee.com/world100/cocoskynet/blob/master/image1.png
        // 远程 url 带图片后缀名
        var remoteUrl = "http://172.16.168.168:8001/images/userface1.jpg";
        cc.loader.load(remoteUrl, function (err, texture) {
            // Use texture to create sprite frame
            cc.log("___https://gitee.com/world100/cocoskynet/blob/master/image1.png___");
            // this.spr.spriteFrame = new cc.SpriteFrame(texture);
        });        
        this.node.emit('foobar', "arg1");

        var n = cc.find("Canvas", this.node);
        cc.log("_________this.node___",n);
        cc.tween(this.node)
        .to(2, { angle: 180})
        .to(2, { angle: 0})
        // .to(1, { scale: 2})
        // 当前面的动作都执行完毕后才会调用这个回调函数
        .call(() => { cc.log('This is a callback') })
        .start()


        this.schedule(function() {
            // 这里的 this 指向 component
            cc.log("_____________定时器____________")
        }, 2);
    }

    onLoad(){
        this.node.on('foobar', function(arg1, arg2){
            cc.log("______hello___",arg1);
        });
    }
}
